package com.zxj.schoolxianyu.service;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zxj.schoolxianyu.dao.followDao;
import com.zxj.schoolxianyu.dao.goodsDao;
import com.zxj.schoolxianyu.entity.follow;
import com.zxj.schoolxianyu.entity.goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class getFollowingGoodsService {

    @Autowired(required = false)
    private followDao followDao;
    @Autowired(required = false)
    private goodsDao goodsDao;

    public String getFollowingGoods(String username) {
        EntityWrapper<follow> f = new EntityWrapper<>();
        EntityWrapper<goods> g = new EntityWrapper<>();
        f.eq("fromusername", username);
        List<follow> fs = followDao.selectList(f);
        List<String> us = new ArrayList<String>();
        for (int i = 0; i < fs.size(); i++) {
            us.add(fs.get(i).tousername);
        }
        g.in("username", us);
        List<goods> gs = goodsDao.selectList(g);
        if (gs.isEmpty()) return "No more data";
        return JSON.toJSONString(gs);
    }
}
